package com.happyass.controller;


import com.happyass.pojo.Booking;
import com.happyass.pojo.Ticket;
import com.happyass.service.BookinfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;

@Controller
@RequestMapping("/book")
public class BookController {

    @Autowired
    BookinfoService bookinfoService;

    //访问购票主页面
    @RequestMapping("/list")
    public String list(Model map,Booking booking, int page){
        //查询所有
        System.err.println(booking);
        HashMap<String,Object> list = bookinfoService.findAll(booking,page);
        map.addAttribute("booksList",list.get("booksList"));
        //设置当前页
        map.addAttribute("nowPage",list.get("nowPage"));
        //获得前一页
        map.addAttribute("lastPage",list.get("lastPage"));
        //获得下一页
        map.addAttribute("nextPage",list.get("nextPage"));
        //获得总页码
        map.addAttribute("conPage",list.get("conPage"));
        //获得货物总数
        map.addAttribute("conEle",list.get("conEle"));
        map.addAttribute("bookingId",booking.getBookingId());
        if(booking.getTicket()!=null)
            map.addAttribute("ticket",booking.getTicket().getTicketId());
        else
            map.addAttribute("ticket",null);
        map.addAttribute("bookingName",booking.getBookingName());
        map.addAttribute("bookdingStatus",booking.getBookdingStatus());
        map.addAttribute("bookingChangeStatus",booking.getBookingChangeStatus());
        map.addAttribute("bookingRefundStatus",booking.getBookingRefundStatus());
        return "/booking-list";
    }

    //删除购票信息
    //删除货物
    @RequestMapping("/delDateBooking")
    @ResponseBody
    public HashMap<String,Object> delDateBooking(int bookingId) {
        HashMap<String,Object> map = new HashMap<String,Object>();
        bookinfoService.delDateBooking(bookingId);
        map.put("info","删除成功");
        return map;
    }


}
